// 装饰器工厂在TS中的使用
const MessageDecoratorFactory = (type?: string): ClassDecorator => {
  let content: string
  switch (type) {
    case 'text':
      content = 'text'
      break
    case 'music':
      content = 'musci'
      break
    default:
      content = 'no message'
  }

  return (target: Function) => {
    target.prototype.message = (): void => {
      console.log(content);
    }
  }
}

{
  @MessageDecoratorFactory('text')
  class Text { }

  @MessageDecoratorFactory('music')
  class Music { }

  @MessageDecoratorFactory()
  class Message { }

  (new Text() as any).message();
  (new Music() as any).message();
  (new Message() as any).message();

}